<%= javascript_include_tag "prototype" %>
<%= javascript_include_tag "util" %>
<%= javascript_include_tag "calendar" %>
    <script type="text/javascript">
        function checkDate()
{
    if ( checkNum(true,'id_serial','id_paper_serial','订单号输入错误') )
        frmSalePaper.submit();
}
function showPaperWindow(id)
{
    window.open("/sale/show_print_sale_paper/"+id,"_blank","height=450,width=700,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}

function checkNum(flag, msg_id, obj_name, msg_text){
    if (flag) {
        if ($(obj_name).value != "" && ! digCheck($(obj_name).value))
        {
            $(msg_id).innerText = msg_text;
            $(msg_id).style.display = "block";
            return false;
        }
        else return true;
    }
    else {
        $(msg_id).style.display = "none";
    }
}

function showAgentWindow(id)
{
    window.open("/other_org/agent_info/"+id,"_blank","height=450,width=500,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
</script>
<h1>订单管理 - <span id="secondHeading"><%='管理订单' if !@type.eql? 'RE'%><%='处理退货' if @type.eql? 'RE'%></span></h1>
<% if @flash[:notice] -%>
<div id="notice"><%= @flash[:notice] %></div>
<% end -%>
<%if !@type.eql? 'RE'%>
<div id="searchBar">
<img src="/images/opened1.gif"><a href="/sale/list_sale_paper?type=UN">显示未处理订单</a>
<img src="/images/locked.gif"><a href="/sale/list_sale_paper?type=ED">显示已处理订单</a>
</div>
<%end%>
<form id="input-form" name="frmSalePaper" action="/sale/list_sale_paper" method="post">
<table id="INPUT_TABLE" style="margin-left:30px;">
<tr>
<td width="15%">
<input type="hidden" name="type" value="<%=@type%>"/> 订&nbsp;单&nbsp;号：&nbsp;
</td>
<td>		
<input id="id_paper_serial" type="text" name="paper_serial" size="20" maxlength="20" onfocus ="checkNum(false,'id_serial')" onblur="checkNum(true,'id_serial',this.id,'订单号输入错误')"/> <div class="redNsg" id="id_serial" style="display:none;"></div>
</td>
</tr>
<tr>
<td>起始时间：</td>
<td>
<script language=javascript>
var beignDate=new dateSelector();
beignDate.inputID='beginDate';
beignDate.inputName='from';
beignDate.display();
</script>
</td>
</tr>
<tr>
<td>结束时间：</td>
<td>
<script language=javascript>
var endDate=new dateSelector();
endDate.inputID='endDate';
endDate.inputName='to';
endDate.display();
</script>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <input type="button" value="查询" class="sub" onclick="checkDate()"/>
                    <input type="hidden" name="papertype" value="<%=@type%>"/>
                </td>
            </tr>
        </table>
    </form>
    <br/>
    <TABLE border="0" id="LIST_TB">
        <TR id="LIST_TB_TITLE">
            <td nowrap>编号</td>
            <td nowrap>销售</td>
            <td nowrap>购买方</td>
            <td>状态</td>
            <td>销售日期</td>
            <td>支付</td>
            <td<%=' colspan="2"' if !@type.eql? 'RE'%>>相关操作</td>
        </tr>
        <%@sale_papers.each do |paper|%>
        <TR id="LIST_TB_CONTENT1">
            <td><a href="javascript:showPaperWindow(<%=paper.id%>)"><%=paper.id%></a></td>
            <td><%=paper.employee.name%></td>
            <td><a href="javascript:showAgentWindow(<%=paper.agent.id%>)"><%=paper.agent.name%></a></td>
            <td><%='<font color="green">已通过</font>' if paper.papertype.eql? 'OK'%> <%='未审批' if paper.papertype.eql? 'UN'%> <%= '<font color="red">未通过</font>' if paper.papertype.eql? 'NO'%> <%='已停用' if paper.papertype.eql? 'CA'%><%='已补齐' if paper.papertype.eql? 'GO'%><%='已完成' if paper.papertype.eql? 'NDFD'%><%='已退货' if paper.papertype.eql? 'RE'%>
                <td><%=paper.sale_date_at%></td>
                <td><%='<font color="red">未支付</font>' if paper.charge.eql? 'no'%><%='<font color="green">已支付</font>' if paper.charge.eql? 'yes'%></td>
                <%if !@type.eql? 'RE'%>
                <td><a href="/sale/show_sale_paper/<%=paper.id%>"><img src="/images/product_info.gif" alt="查看订单详情"></a></td>
                <!--td><%if paper.papertype.eql? 'UN'%><a href="/sale/edit_sale_paper/<%=paper.id%>"><img src="/images/edit.gif" alt="修改订单信息"></a><%end%></td-->
                <td><%if paper.papertype !='NDFD' && paper.papertype !='CA' && paper.papertype !='RE'%><a href="/sale/stop_sale_paper/<%=paper.id%>?papertype=<%=paper.papertype%>" onclick="return confirm('该操作不可逆,您确定作废该订单吗?');"><img src="/images/stop.gif" alt="停用订单"></a><%end%></td>
                <%else%>
                    <%if paper.papertype.eql? 'NDFD' %>
                    <td><a href="/sale/list_sale_paper_item?salePaperId=<%=paper.id%>&type=RE"><img src="/images/product_info.gif" alt="查看订单详情"></a></td>
                    <%else%>
                    <td></td>
                    <%end%>
                <%end%>
            </tr>
            <%end%>
        </table>
        <table>
            <tr>
                <td>
                    <input type="button" value="打印当前页" class="sub" onclick="openPrintWindow('LIST_TB')"/>
                    <input type="button" value="导出当前数据" class="sub" onclick="CellAreaExcel('LIST_TB')"/>
                </td>
                <td>
                    <div class="pagination">
                        <ul>
                            <li class="btn">
                            <%if @sale_paper_pages.current.previous%>
                            <%=link_to("<<上一页", { :page => @sale_paper_pages.current.previous })%>
                            <%else%>
                            <span>&lt;&lt;上一页</span>
                            <%end%>
                            </li>
                            <li><%= pagination_links(@sale_paper_pages) if @sale_paper_pages%></li>
                            <li class="btn">
                            <%if @sale_paper_pages.current.next%>
                            <%=link_to("下一页>>", { :page => @sale_paper_pages.current.next })%>
                            <%else%>
                            <span>下一页&gt;&gt;</span>
                            <%end%>
                            </li>
                        </ul>
                    </div>
                </td>
            </tr>
        </table>
